package com.qyhl.shop.shop.showcase;

import com.qyhl.shop.common.ShopUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.shop.ShopShowcaseBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopShowcaseNoticeBean;

import java.util.List;

public class ShopShowcaseListModel implements ShopShowcaseListContract.ShopShowcaseListModel {
    private ShopShowcaseListPresenter mPresenter;

    public ShopShowcaseListModel(ShopShowcaseListPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(int shopId, int page) {
        EasyHttp.post(ShopUrl.SHOP_SHOWCASE_LIST)
                .params("shopId", shopId + "")
                .params("page", page + "")
                .execute(new SimpleCallBack<List<ShopShowcaseBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取列表失败！");
                    }

                    @Override
                    public void onSuccess(List<ShopShowcaseBean> beanList) {
                        mPresenter.setList(beanList);
                    }
                });
    }

    @Override
    public void getNotice(int shopId) {
        EasyHttp.post(ShopUrl.SHOP_SHOWCASE_NOTICE)
                .params("shopId", shopId + "")
                .execute(new SimpleCallBack<ShopShowcaseNoticeBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setNotice(null);
                    }

                    @Override
                    public void onSuccess(ShopShowcaseNoticeBean bean) {
                        mPresenter.setNotice(bean);
                    }
                });
    }
}
